package org.ss.psci.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.ss.psci.entity.PmBudget;

/**
 * Data access object (DAO) for domain model class PmBudget.
 * 
 * @see org.ss.psci.entity.PmBudget
 * @author MyEclipse Persistence Tools
 */

public class PmBudgetDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PmBudgetDAO.class);
	// property constants
	public static final String BUDGET_TIME = "budgetTime";
	public static final String BUDGET_PRICE = "budgetPrice";
	public static final String MANAGER = "manager";
	public static final String REMARK = "remark";
	public static final String BUDGET_COST = "budgetCost";

	protected void initDao() {
		// do nothing
	}

	public void save(PmBudget transientInstance) {
		log.debug("saving PmBudget instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PmBudget persistentInstance) {
		log.debug("deleting PmBudget instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PmBudget findById(java.lang.Integer id) {
		log.debug("getting PmBudget instance with id: " + id);
		try {
			PmBudget instance = (PmBudget) getHibernateTemplate().get(
					"org.ss.psci.entity.PmBudget", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PmBudget instance) {
		log.debug("finding PmBudget instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PmBudget instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from PmBudget as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByBudgetTime(Object budgetTime) {
		return findByProperty(BUDGET_TIME, budgetTime);
	}

	public List findByBudgetPrice(Object budgetPrice) {
		return findByProperty(BUDGET_PRICE, budgetPrice);
	}

	public List findByManager(Object manager) {
		return findByProperty(MANAGER, manager);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByBudgetCost(Object budgetCost) {
		return findByProperty(BUDGET_COST, budgetCost);
	}

	public List findAll() {
		log.debug("finding all PmBudget instances");
		try {
			String queryString = "from PmBudget";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PmBudget merge(PmBudget detachedInstance) {
		log.debug("merging PmBudget instance");
		try {
			PmBudget result = (PmBudget) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PmBudget instance) {
		log.debug("attaching dirty PmBudget instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PmBudget instance) {
		log.debug("attaching clean PmBudget instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PmBudgetDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PmBudgetDAO) ctx.getBean("PmBudgetDAO");
	}
}